import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { TableColumn } from '@/types/table'
import {DICT_TYPE, getDictOptions, getStrDictOptions} from '@/utils/dict'


// 表单校验
export const rules = reactive({
  // name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
})


//
export const reportTypeOpt= await getStrDictOptions(DICT_TYPE.REPORT_TYPE)
//
export const reportFileTypeOpt=[
  {
    label: '.doc/docx',
    value:'1'
  },
  {
    label: '.pdf',
    value:'2'
  },
]
export const specialtopicTypeOpt= await getDictOptions(DICT_TYPE.TOPICTYPE) // 专题类型

export const resultTypeOpt=[
  {
    label: '震中数据',
    value:'1'
  },
  {
    label: '快速评估影响场数据',
    value:'2'
  },
]
export const externalFileTypeOpt=[
  {
    label: '震源机制解图',
    value:'1'
  },
  {
    label: '推测地震烈度分布图',
    value:'2'
  },
  {
    label: '仪器地震烈度图',
    value:'3'
  },
  {
    label: 'GCMT历史地震矩张量',
    value:'4'
  },
  {
    label: '震源破裂过程图',
    value:'5'
  },
  {
    label: '余震统计',
    value:'6'
  },
  {
    label: '历史地震分布图',
    value:'7'
  },
]
// CrudSchema：https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '报告类型',
    field: 'reportTypes',
    isDetail:true,
    isSearch: false,
    form: {
      component: 'Checkbox',
      value:[],
      componentProps: {
        optionsAlias: {
          labelField: 'label',
          valueField: 'value'
        }
      }
    }
  },
  {
    label: '报告格式',
    field: 'reportFormat',
    isSearch: false,
    isTable:false,
    formatter: (_: Recordable, __: TableColumn, cellValue: number|string) => {
      return reportFileTypeOpt.find((account) => account.value === cellValue)?.label
    },
    form: {
      component: 'Checkbox',
      value:[],
      componentProps: {
          options: reportFileTypeOpt
      }
    }
  },
  {
    label: '专题类型',
    field: 'topicTypes',
    isSearch: false,
    formatter: (_: Recordable, __: TableColumn, cellValue: number|string) => {
      return specialtopicTypeOpt.find((account) => account.value === cellValue)?.label
    },
    form: {
      component: 'Checkbox',
      value:[],
      componentProps: {
          options: specialtopicTypeOpt
      }
    }
  },
  {
    label: '结果数据',
    field: 'resultData',
    isSearch: false,
    formatter: (_: Recordable, __: TableColumn, cellValue: number|string) => {
      return resultTypeOpt.find((account) => account.value === cellValue)?.label
    },
    form: {
      component: 'Checkbox',
      value:[],
      componentProps: {
          options: resultTypeOpt
      }
    }
  },
  {
    label: '外部文件',
    field: 'outsideFiles',
    isSearch: false,
    isTable:false,
    formatter: (_: Recordable, __: TableColumn, cellValue: number|string) => {
      return externalFileTypeOpt.find((account) => account.value === cellValue)?.label
    },
    form: {
      component: 'Checkbox',
      value:[],
      componentProps: {
          options: externalFileTypeOpt
      }
    }
  },
  {
    label: '操作',
    field: 'action',
    isDetail: false,
    isForm:false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
